<template>
  <div class="monitor-detail-redar">
  	<div class="monitor-radar-title detail-title">
		雷达
	</div>
	<div class="monitor-radar-content detail-content">
		<div v-for="(item, index) in radar">
			<div class="content-title detail-content-title">
				{{ item.title }}
			</div>
			<div class="content-lab detail-content-lab">
				<div  v-for="(items, indexs) in item.content" :title="items.name" @click="activeRadar(item, items)" :class="{active: items.active}">
					{{ items.name }}
				</div>
			</div>
		</div>
	</div>
	<div class="monitor-radar-close detail-close" @click="closeRadar">
		×
	</div>
	<common ref="common"></common>
  </div>
</template>

<script>
import common from '../common'
import {getMonitorRadar, HTTPG, HTTPY} from '../../mock/mockdata.js'
export default {
	props: {
		initTime: {
			type: String,
		}
	},
	data() {
		return {
			radar: [],
			storeRadar: {},
		}
	},
	components: {
		common
	},
	created() {
		this.radar = getMonitorRadar
		this.radar.forEach((obj) => {
			obj.content.forEach((data) => {
				if(data.active){
					this.storeRadar = data
				}
			})
		})
	},
	mounted() {
	},
	watch: {
		initTime: {
			handler: function(val, oldval) {
				this.getLastTime()
			}
		}
	},
	methods: {
		closeRadar() {
			this.$emit('close-radar')
		},
		activeRadar(data, res) {
			this.radar.forEach((obj) => {
				obj.content.forEach((data) =>{
					data.active = false
				})
			})
			res.active = true
			this.storeRadar = res

			this.getLastTime()
		},
		getLastTime() {
			let endTime = this.initTime.replace(/\-/g,'').replace(/\:/g,'').replace(' ','')
			let startTime = this.$refs.common.getTimeCShow(endTime, -12*60)
			if(this.storeRadar.titleOf === '雷达回波'){
				let imageProductOptions = {
		        	productcategory: this.storeRadar.type,
		       	 	begintime: startTime,
		        	endtime: endTime
		    	}
		    	let that = this
		    	let products = QXMap.GetImageProductList(imageProductOptions, function (data) {
		    		if(data.DS.length !== 0){
		        		that.$emit("radar-change", data.DS, that.storeRadar)
		        	}
		        })
			}else if(this.storeRadar.titleOf === '降水'){
				let ajaxUrl= HTTPY.url + "RADA_L3_MST_QPE/getContourValidtimeListByTime"
					+"?userid="+ HTTPY.userid +"&pwd=123&productcategory="+this.storeRadar.type+"&fcstlevel=0&time="+endTime+"&timetype=D&admincodes=330000&elements=time&limitcnt=200&dataformat=json"
				this.$http.get(ajaxUrl)
				.then((res)=>{
					if(res.body.DS.length !== 0){
						this.$emit("radar-change", res.body.DS, this.storeRadar)
					}
				},(err) => {

				})
			}
		},
		productAddRadar(res) {
			//console.log('进入雷达页面')
		}
	}
}
</script>

<style>

</style>
